package com.aidex.biz.controller;

import com.aidex.biz.domain.RxkOrder;
import com.aidex.biz.service.RxkOrderService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 融享客客户订单Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/biz/bizRxkOrder")
public class RxkOrderController extends BaseController
{
    @Autowired
    private RxkOrderService rxkOrderService;

    /**
     * 查询融享客客户订单列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:list')")
    @GetMapping("/list")
    public R<PageInfo> list(RxkOrder rxkOrder, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                rxkOrder.setCompanyId(null);
        }else{
                     rxkOrder.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        rxkOrder.setPage(new PageDomain(request, response));
        return R.data(rxkOrderService.findPage(rxkOrder));
    }

    /**
     * 获取融享客客户订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:query')")
    @GetMapping(value = "/{id}")
    public R<RxkOrder> detail(@PathVariable("id") String id)
    {
        return R.data(rxkOrderService.get(id));
    }

    /**
     * 新增融享客客户订单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:add')")
    @Log(title = "融享客客户订单", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  RxkOrder rxkOrder)
    {
        return R.status(rxkOrderService.save(rxkOrder));
    }

    /**
     * 修改融享客客户订单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:edit')")
    @Log(title = "融享客客户订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated RxkOrder rxkOrder)
    {
        return R.status(rxkOrderService.save(rxkOrder));
    }


    /**
     * 删除融享客客户订单
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:remove')")
    @Log(title = "融享客客户订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(rxkOrderService.deleteRxkOrderByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(rxkOrderService.findMaxSort(new RxkOrder()));
    }

    /**
     * 导出融享客客户订单列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizRxkOrder:export')")
    @Log(title = "融享客客户订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(RxkOrder rxkOrder)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    rxkOrder.setCompanyId(null);
            }else{
                         rxkOrder.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<RxkOrder> list = rxkOrderService.findList(rxkOrder);
        ExcelUtil<RxkOrder> util = new ExcelUtil<RxkOrder>(RxkOrder.class);
        return util.exportExcel(list, "融享客客户订单数据");
    }

}
